#include "qsspage.h"

#include <QVBoxLayout>
#include <QPushButton>
#include <QDebug>
#include <QIcon>
#include <QTimer>
#include <QFile>
#include <QComboBox>
#include <QLineEdit>

QSSPage::QSSPage(QWidget *parent)
    : QWidget(parent)
    , m_skinType(0)
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    setLayout(mainLayout);

    QPushButton *skinTurnBtn = new QPushButton("切换皮肤", this);
    mainLayout->addWidget(skinTurnBtn);

    QWidget *skinWidget = new QWidget(this);
    mainLayout->addWidget(skinWidget);

    QVBoxLayout *skinLayout = new QVBoxLayout();
    skinWidget->setLayout(skinLayout);

    QPushButton *btn1 = new QPushButton(this);
    btn1->setText("******1");
    skinLayout->addWidget(btn1);

    QPushButton *btn2 = new QPushButton(this);
    btn2->setText("******2");
    skinLayout->addWidget(btn2);

    QComboBox *comboBox = new QComboBox(this);
    comboBox->addItems({"1", "adfasf", "oijion"});
    skinLayout->addWidget(comboBox);

    QLineEdit *edit = new QLineEdit(this);
    edit->setText("dsfasfas");
    skinLayout->addWidget(edit);

    // qss init
    QFile qssFile("://qss/qss1.qss");
    if (!qssFile.open(QIODevice::OpenModeFlag::ReadOnly)) {
        qCritical() << Q_FUNC_INFO << qssFile.fileName() << "open failed!";
        return;
    }

    m_qssDateList << qssFile.readAll();
    qssFile.close();

    qssFile.setFileName("://qss/qss2.qss");
    if (!qssFile.open(QIODevice::OpenModeFlag::ReadOnly)) {
        qCritical() << Q_FUNC_INFO << qssFile.fileName() << "open failed!";
        return;
    }

    m_qssDateList << qssFile.readAll();
    qssFile.close();

    // init connect
    connect(skinTurnBtn, &QPushButton::clicked, this , [this, skinWidget] {
        m_skinType = (m_skinType + 1) % 2;
        if (m_qssDateList.size() - 1 < m_skinType) {
            m_skinType = m_qssDateList.size() - 1;
        }
        if (0 == m_skinType) {
            skinWidget->setStyleSheet(m_qssDateList[m_skinType]);
        } else {
            skinWidget->setStyleSheet(m_qssDateList[m_skinType]);
        }
    });

}

QSSPage::~QSSPage()
{
}
